SG Window | Window Object |
SendKeys Method |
Properties Methods Events Constants Error Codes |
Sends one or more keystrokes to the window as if typed at the keyboard.
object.SendKeys(keys As String, Optional wait As Boolean = True, Optional activeWin As Boolean = False)
Part | Description |
object | The object is expression that evaluates to Window object |
keys | Required. String specifying the keystrokes to send. |
wait | Optional. If True keystrokes are processed before control is returned to the caller. If False control is returned to the caller as soon as keystrokes are sent. Default value is True. |
activeWin | Optional. If True keystrokes are sent to the currently active window. If False keystrokes are sent to the window attached to Window object. Default value is False. |
Keystrokes string contains keys represented with one or more characters. Keyboard characters are represented by themselves. For example, character string "AB" represents letters A and B.
The plus sign (+), caret (^), percent sign (%), tilde (~), and parentheses () have special meanings to SendKeys. To specify one of these characters, enclose it within braces ({}). For example, to specify the plus sign, use {+}. To specify brace characters, use {{} and {}}.
To specify other keys use codes in this table:
Key | Code |
SHIFT | + |
CTRL | ^ |
ALT | % |
BACKSPACE | {BACKSPACE}, {BS}, or {BKSP} |
BREAK | {BREAK} |
CAPS LOCK | {CAPSLOCK} |
DEL or DELETE | {DELETE} or {DEL} |
DOWN ARROW | {DOWN} |
END | {END} |
ENTER | {ENTER} or ~ |
ESC | {ESC} |
HELP | {HELP} |
HOME | {HOME} |
INS or INSERT | {INSERT} or {INS} |
LEFT ARROW | {LEFT} |
NUM LOCK | {NUMLOCK} |
PAGE DOWN | {PGDN} |
PAGE UP | {PGUP} |
PRINT SCREEN | {PRTSC} |
RIGHT ARROW | {RIGHT} |
SCROLL LOCK | {SCROLLLOCK} |
TAB | {TAB} |
UP ARROW | {UP} |
F1 | {F1} |
F2 | {F2} |
F3 | {F3} |
F4 | {F4} |
F5 | {F5} |
F6 | {F6} |
F7 | {F7} |
F8 | {F8} |
F9 | {F9} |
F10 | {F10} |
F11 | {F11} |
F12 | {F12} |
F13 | {F13} |
F14 | {F14} |
F15 | {F15} |
F16 | {F16} |
To specify repeating keys, use the form {key number}. You must put a space between key and number. For example, {LEFT 42} means press the LEFT ARROW key 42 times; {h 10} means press H 10 times.
Following example shows how to use SendKeys from VBScript script. It starts standard file find dialog and serches for files named NOTEPAD.EXE.
Dim wnd, desktop, g Set desktop = CreateObject("SGWindow.Window") Set g = CreateObject("SGWindow.Globals")
desktop.AttachDesktop ' Activate FileFind dialog Set wnd = desktop.FindWindow("Progman", "") wnd.SendKeys "{F3}", true, true ' Wait for FileFind to pop up g.sleep 1000 ' Start search wnd.SendKeys "notepad.exe{TAB 2}c+;\~", true, true